<?php
/**
 * Created by PhpStorm.
 * User: czw
 * Date: 2018/7/11
 * Time: 14:59
 */
namespace app\common\model;


use app\lib\exception\BaseException;
use app\lib\exception\CreateException;
use app\lib\exception\DeleteException;

class AdminRole extends BaseModel
{
    protected $hidden = ['delete_time'];
    public static function matchRole($data){
        $row = self::where($data)->find();

        if($row) throw (new BaseException(['msg'=>'已经关联，无需再次关联！']));
        $res = self::create($data);
        if(!$res) throw (new CreateException());
    }
    public static function unMatchRole($data){
        $res = self::where($data)->delete(true);
        if(!$res) throw (new DeleteException());
    }


}